package com.awise.app.more.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.awise.R;
import com.awise.base.BaseActivity;


/**
 * Created by lgz on 2018/1/23.
 */

public class ControlNumberActivity extends BaseActivity implements View.OnClickListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.more_control_number_layout);
        initView();
    }
    RelativeLayout rl_control_number_first,rl_control_number_second,rl_control_number_third,
            rl_control_number_forth,rl_control_number_fifth;
    ImageView cb_control_number_first,cb_control_number_second,cb_control_number_third,
            cb_control_number_forth,cb_control_number_fifth;
    private void initView() {
        TextView s_back = (TextView) this.findViewById(R.id.tv_back);
        s_back.setVisibility(View.VISIBLE);
        s_back.setOnClickListener(this);
        TextView textView_content = (TextView) this.findViewById(R.id.textView_content);
        textView_content.setText(R.string.control_number);
        rl_control_number_first = (RelativeLayout) this.findViewById(R.id.rl_control_number_first);
        rl_control_number_second = (RelativeLayout) this.findViewById(R.id
                .rl_control_number_second);
        rl_control_number_third = (RelativeLayout) this.findViewById(R.id.rl_control_number_third);
        rl_control_number_fifth = (RelativeLayout) this.findViewById(R.id.rl_control_number_fifth);
        rl_control_number_forth = (RelativeLayout) this.findViewById(R.id.rl_control_number_forth);
        rl_control_number_first.setOnClickListener(this);
        rl_control_number_second.setOnClickListener(this);
        rl_control_number_third.setOnClickListener(this);
        rl_control_number_fifth.setOnClickListener(this);
        rl_control_number_forth.setOnClickListener(this);
        cb_control_number_first = (ImageView) this.findViewById(R.id.cb_control_number_first);
        cb_control_number_second = (ImageView) this.findViewById(R.id.cb_control_number_second);
        cb_control_number_third = (ImageView) this.findViewById(R.id.cb_control_number_third);
        cb_control_number_forth = (ImageView) this.findViewById(R.id.cb_control_number_forth);
        cb_control_number_fifth = (ImageView) this.findViewById(R.id.cb_control_number_fifth);
        int number= getSP(this,"ControlNumber", 5);
        switch (number){
            case 1:
                setFirstNumber();
                break;
            case 2:
                setFirstNumber();
                break;
            case 3:
                setThirdNumber();
                break;
            case 4:
                setForthNumber();
                break;
            case 5:
                setFifthNumber();
                break;
            default:
                setFirstNumber();
                setSP(this,"ControlNumber",5);
                break;
        }

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.tv_back:
                Intent intent = new Intent();
                int number= getSP(this,"ControlNumber", 5);
                intent.putExtra("number",number);
                setResult(RESULT_OK,intent);
                finish();
                break;
            case R.id.rl_control_number_first:
               setFirstNumber();
                setSP(this,"ControlNumber",1);
                break;
            case R.id.rl_control_number_second:
                setSecondNumber();
                setSP(this,"ControlNumber",2);
                break;
            case R.id.rl_control_number_third:
                setThirdNumber();
                setSP(this,"ControlNumber",3);
                break;
            case R.id.rl_control_number_forth:
                setForthNumber();
                setSP(this,"ControlNumber",4);
                break;
            case R.id.rl_control_number_fifth:
                setFifthNumber();
                setSP(this,"ControlNumber",5);
                break;
        }
    }

    private void setFifthNumber() {
        rl_control_number_first.setBackgroundColor(getResources().getColor(R.color.color_check_back_false));
        rl_control_number_second.setBackgroundColor(getResources().getColor(R.color.color_check_back_false));
        rl_control_number_third.setBackgroundColor(getResources().getColor(R.color.color_check_back_false));
        rl_control_number_forth.setBackgroundColor(getResources().getColor(R.color.color_check_back_false));
        rl_control_number_fifth.setBackgroundColor(getResources().getColor(R.color.color_check_back_true));
        cb_control_number_first.setVisibility(View.INVISIBLE);
        cb_control_number_second.setVisibility(View.INVISIBLE);
        cb_control_number_third.setVisibility(View.INVISIBLE);
        cb_control_number_forth.setVisibility(View.INVISIBLE);
        cb_control_number_fifth.setVisibility(View.VISIBLE);
    }

    private void setForthNumber() {
        rl_control_number_first.setBackgroundColor(getResources().getColor(R.color.color_check_back_false));
        rl_control_number_second.setBackgroundColor(getResources().getColor(R.color.color_check_back_false));
        rl_control_number_third.setBackgroundColor(getResources().getColor(R.color.color_check_back_false));
        rl_control_number_forth.setBackgroundColor(getResources().getColor(R.color.color_check_back_true));
        rl_control_number_fifth.setBackgroundColor(getResources().getColor(R.color.color_check_back_false));
        cb_control_number_first.setVisibility(View.INVISIBLE);
        cb_control_number_second.setVisibility(View.INVISIBLE);
        cb_control_number_third.setVisibility(View.INVISIBLE);
        cb_control_number_forth.setVisibility(View.VISIBLE);
        cb_control_number_fifth.setVisibility(View.INVISIBLE);
    }

    private void setThirdNumber() {
        rl_control_number_first.setBackgroundColor(getResources().getColor(R.color.color_check_back_false));
        rl_control_number_second.setBackgroundColor(getResources().getColor(R.color.color_check_back_false));
        rl_control_number_third.setBackgroundColor(getResources().getColor(R.color.color_check_back_true));
        rl_control_number_forth.setBackgroundColor(getResources().getColor(R.color.color_check_back_false));
        rl_control_number_fifth.setBackgroundColor(getResources().getColor(R.color.color_check_back_false));
        cb_control_number_first.setVisibility(View.INVISIBLE);
        cb_control_number_second.setVisibility(View.INVISIBLE);
        cb_control_number_third.setVisibility(View.VISIBLE);
        cb_control_number_forth.setVisibility(View.INVISIBLE);
        cb_control_number_fifth.setVisibility(View.INVISIBLE);
    }

    private void setSecondNumber() {
        rl_control_number_first.setBackgroundColor(getResources().getColor(R.color.color_check_back_false));
        rl_control_number_second.setBackgroundColor(getResources().getColor(R.color.color_check_back_true));
        rl_control_number_third.setBackgroundColor(getResources().getColor(R.color.color_check_back_false));
        rl_control_number_forth.setBackgroundColor(getResources().getColor(R.color.color_check_back_false));
        rl_control_number_fifth.setBackgroundColor(getResources().getColor(R.color.color_check_back_false));
        cb_control_number_first.setVisibility(View.INVISIBLE);
        cb_control_number_second.setVisibility(View.VISIBLE);
        cb_control_number_third.setVisibility(View.INVISIBLE);
        cb_control_number_forth.setVisibility(View.INVISIBLE);
        cb_control_number_fifth.setVisibility(View.INVISIBLE);
    }

    private void setFirstNumber() {
        rl_control_number_first.setBackgroundColor(getResources().getColor(R.color.color_check_back_true));
        rl_control_number_second.setBackgroundColor(getResources().getColor(R.color.color_check_back_false));
        rl_control_number_third.setBackgroundColor(getResources().getColor(R.color.color_check_back_false));
        rl_control_number_forth.setBackgroundColor(getResources().getColor(R.color.color_check_back_false));
        rl_control_number_fifth.setBackgroundColor(getResources().getColor(R.color.color_check_back_false));
        cb_control_number_first.setVisibility(View.VISIBLE);
        cb_control_number_second.setVisibility(View.INVISIBLE);
        cb_control_number_third.setVisibility(View.INVISIBLE);
        cb_control_number_forth.setVisibility(View.INVISIBLE);
        cb_control_number_fifth.setVisibility(View.INVISIBLE);
    }

}
